<?php include './header.php';

if (isset($_GET['user_id'])) {
    $id = $_GET['user_id'];
    $select_condition = "WHERE admin_id = $id";
    $admin = $db->selectOne('admin', '*', $select_condition);
}


if(isset($_POST['edit'])){
    $update_condition = "WHERE admin_id = $id";
    $value = '';
//     pre($_POST);die;
    
    foreach($_POST as $key => $val){
        if($val != '' && $val != '提交'){
            $value .= '`'.$key.'`'."='".$val."',";
        }
    }

    $time = time();
    $value = $value."`admin_last_login` = '$time'";
    if($db->update('admin', $value, $update_condition)){
        echo "<script>alert('修改成功!');window.location.href='user_list.php';</script>";
        $login->delSession($_SESSION);
        $login->isLogin();
    }
    
}



?>
<!-- Start: Content -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-fileinput.css" rel="stylesheet">
<section id="content">
    <div id="topbar" class="affix">
        <ol class="breadcrumb">
            <li><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
            <li class="active">修改用户信息</li>
        </ol>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-lg-8 center-column">
                <form action="" method="post" class="cmxform" enctype="multipart/form-data">
                    <div class="panel">
                        <div class="panel-heading">
                            <div class="panel-title">编辑用户信息</div>
                            <div class="panel-btns pull-right margin-left">
                                <a href="#" onclick="window.history.back();" class="btn btn-default btn-gradient dropdown-toggle"><span class="glyphicon glyphicon-chevron-left"></span></a>
                            </div>
                        </div>
                        <div class="panel-body">
                            <div class="col-md-7">
                                <div class="form-group">
                                    <div class="input-group"><span class="input-group-addon">用&ensp;户&ensp;名</span>
                                    <input type="text" name="admin_name" value="<?php echo $admin['admin_name']; ?>" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group"><span class="input-group-addon">密&emsp;&emsp;码</span>
                                        <input type="text" name="pwd" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="input-group"><span class="input-group-addon">确认密码</span>
                                        <input type="text" name="confirm_pwd" class="form-control">
                                    </div>
                                </div>
                                
                            </div>
                            
                            <div class="col-md-7">
                                <div class="form-group">
                                    <input type="submit" value="提交" name="edit" class="submit btn btn-blue">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
</section>
<!-- End: Content -->
</div>
<!-- End: Main -->
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap-fileinput.js"></script>
<link type="text/css" rel="stylesheet" href="umeditor/themes/default/_css/umeditor.css">
<script src="umeditor/umeditor.config.js" type="text/javascript"></script>
<script src="umeditor/editor_api.js" type="text/javascript"></script>
<script src="umeditor/lang/zh-cn/zh-cn.js" type="text/javascript"></script>
<script type="text/javascript">
    var ue = UM.getEditor('myEditor', {
        autoClearinitialContent: false,
        wordCount: false,
        elementPathEnabled: false,
        initialFrameHeight: 300
    });
</script>
</body>

</html>